package com.insigma.business.qrcode.merchant.bff.impl;

import cn.hutool.core.bean.BeanUtil;
import com.insigma.business.qrcode.common.template.BasePagingResponse;
import com.insigma.business.qrcode.common.util.BizCheckUtil;
import com.insigma.business.qrcode.common.util.SessionUtils;
import com.insigma.business.qrcode.common.vo.BaseDeleteRequest;
import com.insigma.business.qrcode.common.vo.BaseResponse;
import com.insigma.business.qrcode.soldier.dto.gov.BaseProviderImpl;
import com.insigma.business.qrcode.common.template.area.ScenarioCodeEnum;
import com.insigma.business.qrcode.common.template.area.ServiceCallback;
import com.insigma.business.qrcode.soldier.request.BaseGetRequest;
import com.insigma.business.qrcode.welfare.dto.CareWelfareMerchantStreetDTO;
import com.insigma.business.qrcode.merchant.dto.request.CareWelfareMerchantStreetInsertRequest;
import com.insigma.business.qrcode.merchant.dto.request.CareWelfareMerchantStreetRelInsertRequest;
import com.insigma.business.qrcode.merchant.dto.request.CareWelfareMerchantStreetSearchRequest;
import com.insigma.business.qrcode.merchant.bff.CareWelfareMerchantStreetBFFProvider;
import com.insigma.business.qrcode.merchant._consumer.CareWelfareMerchantStreetConsumer;
import com.insigma.business.qrcode.merchant._consumer.CareWelfareMerchantStreetRelConsumer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@Component("careWelfareMerchantStreetBFFProvider")
public class CareWelfareMerchantStreetBFFProviderImpl extends BaseProviderImpl implements CareWelfareMerchantStreetBFFProvider {


        @Autowired
        private CareWelfareMerchantStreetConsumer careWelfareMerchantStreetConsumer;

    @Autowired
    private CareWelfareMerchantStreetRelConsumer careWelfareMerchantStreetRelConsumer;


    @Override
    public BasePagingResponse<List<CareWelfareMerchantStreetDTO>> searchCareWelfareMerchantStreet(final CareWelfareMerchantStreetSearchRequest searchRequest) {

        final BasePagingResponse<List<CareWelfareMerchantStreetDTO>> basePagingResponse = new BasePagingResponse<>();
        serviceTemplate.execute(basePagingResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(searchRequest, "查询分页CareWelfareMerchantStreet的请求参数不能为空");
            }

            @Override
            public void executeService() {
                BasePagingResponse<List<CareWelfareMerchantStreetDTO>> listBasePagingResponse = careWelfareMerchantStreetConsumer.searchCareWelfareMerchantStreet(searchRequest);
                BeanUtil.copyProperties(listBasePagingResponse, basePagingResponse);
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CARE_WELFARE_MERCHANT_STREET_SEARCH;
            }
        });

        return basePagingResponse;
    }

    @Override
    public BaseResponse<CareWelfareMerchantStreetDTO> getCareWelfareMerchantStreet(BaseGetRequest baseGetRequest) {
        final BaseResponse<CareWelfareMerchantStreetDTO> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(baseGetRequest, "获取单条CareWelfareMerchantStreet的请求参数不能为空");
                BizCheckUtil.checkNotBlank((String)baseGetRequest.getId(), "id不能为空");
            }

            @Override
            public void executeService() {
                final BaseResponse<CareWelfareMerchantStreetDTO> careWelfareMerchantStreetResponse = careWelfareMerchantStreetConsumer.getCareWelfareMerchantStreet(baseGetRequest);
                BeanUtil.copyProperties(careWelfareMerchantStreetResponse, baseResponse);
            }
            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CARE_WELFARE_MERCHANT_STREET_GET;
            }
        });
        return baseResponse;
    }

    @Override
    public BaseResponse<String> insertCareWelfareMerchantStreetRel(CareWelfareMerchantStreetRelInsertRequest insertRequest) {
        SessionUtils.buildCreatorOfGov(insertRequest);
        return careWelfareMerchantStreetRelConsumer.insertCareWelfareMerchantStreetRel(insertRequest);
    }

    @Override
    public BaseResponse<Integer> deleteCareWelfareMerchantStreet(BaseDeleteRequest deleteRequest) {
        final BaseResponse<Integer> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(transactionTemplate, baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(deleteRequest, "逻辑删除CareWelfareMerchantStreet的请求参数不能为空");
                BizCheckUtil.checkNotBlank((String)deleteRequest.getId(), "id不能为空");
            }
            @Override
            public void executeService() {
                SessionUtils.buildDeleteOfGov(deleteRequest);
                BaseResponse<Integer> careWelfareMerchantStreetResponse = careWelfareMerchantStreetConsumer.deleteCareWelfareMerchantStreet(deleteRequest);
                BeanUtil.copyProperties(careWelfareMerchantStreetResponse, baseResponse);
            }
            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CARE_WELFARE_MERCHANT_STREET_DELETE_LOGICALLY;
            }
        });
        return baseResponse;    }

    @Override
    public BaseResponse<String> insertCareWelfareMerchantStreet(CareWelfareMerchantStreetInsertRequest insertRequest) {
        final BaseResponse<String> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(transactionTemplate, baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(insertRequest, "新增CareWelfareMerchantStreet的请求参数不能为空");
            }
            @Override
            public void executeService() {
                SessionUtils.buildCreatorOfGov(insertRequest);
                BaseResponse<String> careWelfareMerchantStreetResponse = careWelfareMerchantStreetConsumer.insertCareWelfareMerchantStreet(insertRequest);
                BeanUtil.copyProperties(careWelfareMerchantStreetResponse, baseResponse);
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CARE_WELFARE_MERCHANT_STREET_INSERT;
            }
        });
        return baseResponse;
    }


}
